﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<!DOCTYPE html>
<html lang="en">
	<head>
	<style type="text/css">
		.columnDiv{
			position:absolute; /*绝对定位*/ 
			top:5%; /*距顶部50%*/ 
			left:10%; 
			margin:0 0 0 0; /*设定这个div的margin-top的负值为自身的高度的一半,margin-left的值也是自身的宽度的一半的负值.(感觉在绕口令)*/ 
			width:200px; /*宽为400,那么margin-top为-200px*/ 
			height:300px; /*高为200那么margin-left为-100px;*/ 
			z-index:9999; /*浮动在最上层 */ 
			border :1px solid grey;
			background-color:white;
		}
	</style>
	<!-- jsp文件头和头部 -->
	<%@ include file="../../top.jsp"%> 
	</head> 
<body>
		
<div class="container-fluid" id="main-container">


<div id="page-content" class="clearfix">
						
  <div class="row-fluid">


	<div class="row-fluid">
	
			<!-- 检索  -->
			<!-- <iframe name="mainFrame" id="mainFrame" frameborder="0" src="tab.do" style="margin:0 auto;width:100%;height:100%;"></iframe> -->
			<table>
				<tr>
					<td>
						<span class="input-icon">
							<input autocomplete="off" id="nav-search-input" type="text" name="USERNAME" value="${pd.USERNAME }" placeholder="这里输入关键词" />
							<i id="nav-search-icon" class="icon-search"></i>
						</span>
					</td>
					<td><input class="span10 date-picker" name="lastLoginStart" id="lastLoginStart"  value="${pd.lastLoginStart}" type="text" data-date-format="yyyy-mm-dd" readonly="readonly" style="width:88px;" placeholder="开始日期" title="最近登录开始"/></td>
					<td><input class="span10 date-picker" name="lastLoginEnd" id="lastLoginEnd"  value="${pd.lastLoginEnd}" type="text" data-date-format="yyyy-mm-dd" readonly="readonly" style="width:88px;" placeholder="结束日期" title="最近登录结束"/></td>
					<td id="buttonlabel" style="vertical-align:top;padding-top: 5px;">状态:</td>
					<td style="vertical-align:top;padding-top: 4px;">
							<label  class="label-style"> <input
								name="F_STATUS" type="radio" id="yes" value="0"
								class="singleInput"  checked/><span class="lbl">正常</span>

							</label> <label class="label-style"> <input name="F_STATUS" type="radio"
								id="no" value="1" class="singleInput" /><span class="lbl">停用</span>
							</label>
					</td>
					<td style="vertical-align:top;"><button class="btn btn-mini btn-light" onclick="search();" title="检索"><i id="nav-search-icon" class="icon-search"></i></button></td>
				</tr>
			</table>
			<!-- 检索  -->
		
		
		<table id="userTable" class="table table-striped table-bordered table-hover"></table>	
		<!-- <button onclick="showColumDiv();">test</button> -->
		<div class="page-header position-relative">
		<table style="width:100%;">
			<tr>
				<td style="vertical-align:top;">
<%-- 					<c:if test="${QX.add == 1 }"> --%>
					<a class="btn btn-small btn-success" onclick="add();">新增</a>
<%-- 					</c:if> --%>
<%-- 					<c:if test="${QX.del == 1 }"> --%>
					<a title="批量删除" class="btn btn-small btn-danger" onclick="makeAll('确定要删除选中的数据吗?');" ><i class='icon-trash'></i></a>
<%-- 					</c:if> --%>
				</td>
			</tr>
		</table>
		</div>
	</div>
 
 
 
 
	<!-- PAGE CONTENT ENDS HERE -->
  </div><!--/row-->
	
</div><!--/#page-content-->
</div><!--/.fluid-container#main-container-->
		
		<!-- 返回顶部  -->
		<a href="#" id="btn-scroll-up" class="btn btn-small btn-inverse">
			<i class="icon-double-angle-up icon-only"></i>
		</a>
		
		<script type="text/javascript">
		var del_flag='0';//默认未删除
		$(top.hangge());
		
		//新增
		function add(){
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="新增";
			 diag.URL = '<%=basePath%>user/goAddU.do';
			 diag.Width = 800;
			 diag.Height = 500;
		 	 diag.CancelEvent = function(){ //关闭事件
				 search();//刷新页面
				diag.close();
			 };  
			
			 diag.show();
		}
		
		//修改
		function editUser(user_id){
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="修改";
			 diag.URL = '<%=basePath%>user/goEditU.do?USER_ID='+user_id;
			 diag.Width = 800;
			 diag.Height = 500;
			 diag.CancelEvent = function(){ //关闭事件
				 search();
				diag.close();
			 };
			 diag.show();
		}
		
		//删除
		function delUser(userId){
			bootbox.dialog("您确定要删除这条记录吗!", [ {
				"label" : "确定",
				"class" : "btn-small btn-success",
				"callback" : function(e) {
					top.jzts();
					var url = "<%=basePath%>user/deleteU.do?USER_ID="+userId+"&tm="+new Date().getTime();
					$.get(url,function(data){
						 top.hangge();
						 if(data=='success'){
						 bootbox.dialog("删除成功!", 
									[
									  {
										"label" : "关闭",
										"class" : "btn-small btn-success",
										"callback": function() {
											search();
											}
										}
									 ]
								);
						 }else{
							bootbox.alert("删除失败"); 
						 }
				});
				}
			} ,
			{
				"label" : "取消",
				"class" : "btn-small btn-success",
				"callback" : function(e) {
				}
			}
			])
		}
		
		
		//恢复
		function revertUser(userId){
			bootbox.dialog("您确定要恢复这条记录吗!", [ {
				"label" : "确定",
				"class" : "btn-small btn-success",
				"callback" : function(e) {
					top.jzts();
					var url = "<%=basePath%>user/revertUser.do?USER_ID="+userId+"&tm="+new Date().getTime();
					$.get(url,function(data){
						 top.hangge();
						 if(data=='success'){
						 bootbox.dialog("恢复成功!", 
									[
									  {
										"label" : "关闭",
										"class" : "btn-small btn-success",
										"callback": function() {
											search();
											}
										}
									 ]
								);
						 }else{
							bootbox.alert("恢复失败"); 
						 }
				});
				}
			} ,
			{
				"label" : "取消",
				"class" : "btn-small btn-success",
			}
			])
		}
		//批量操作
		function makeAll(msg){
			
			bootbox.confirm(msg, function(result) {
				if(result) {
					var indexes = $("#userTable").bootstrapTable('getSelections').length;
					var users =$("#userTable").bootstrapTable('getSelections');
					var str = "";
					var emstr = '';
					var phones = '';
					for(var i=0;i < indexes;i++){
						if(i!=indexes-1){
							str += users[i].user_ID+",";
						}else{
							str += users[i].user_ID;
						}
						
						}
					if(str==''){
						bootbox.dialog("您没有选择任何内容!", 
							[
							  {
								"label" : "关闭",
								"class" : "btn-small btn-success",
								
								}
							 ]
						);
						
						return;
					}else{
						if(msg == '确定要删除选中的数据吗?'){
							top.jzts();
							 $.ajax({
								type: "POST",
								url: '<%=basePath%>user/deleteAllU.do?tm='+new Date().getTime(),
						    	data: {USER_IDS:str},
								dataType:'json',
								//beforeSend: validateData,
								cache: false,
								success: function(data){
									 top.hangge();
									 bootbox.dialog("删除成功!", 
												[
												  {
													"label" : "关闭",
													"class" : "btn-small btn-success",
													"callback": function() {
														search();
														}
													}
												 ]
											);
								}
							}); 
						}
						
						
					}
				}
			});
		}
		</script>
		
		<script type="text/javascript">
		
		$(function() {
			
			//日期框
			$('.date-picker').datepicker();
			
			//下拉框
			$(".chzn-select").chosen(); 
			$(".chzn-select-deselect").chosen({allow_single_deselect:true}); 
			
			//复选框
			$('table th input:checkbox').on('click' , function(){
				var that = this;
				$(this).closest('table').find('tr > td:first-child input:checkbox')
				.each(function(){
					this.checked = that.checked;
					$(this).closest('tr').toggleClass('selected');
				});
					
			});
			
			initTable();
		});
		var columns = ['user_ID,ID','number,编号','username,用户名','name,姓名','role_NAME,职位','email,邮箱','last_LOGIN,最近登录','ip,上次登录IP'];
		function initTable(){
					
					$('#userTable').bootstrapTable('destroy');
					
					$('#userTable').bootstrapTable({
							contentType: "application/x-www-form-urlencoded",
							  url: '<%=basePath%>user/userTable.do',
							  method: 'post', //请求方式（*）
								striped: true, //是否显示行间隔色
								cache: false, //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
								pagination: true, //是否显示分页（*）
								sortable: false, //是否启用排序
								sortOrder: "asc", //排序方式
								singleSelect : false,
								queryParams: queryParams, //传递参数（*）
								sidePagination: "server", //分页方式：client客户端分页，server服务端分页（*）
								queryParamsType : "limit",
								pageNumber: 1, //初始化加载第一页，默认第一页
								pageSize: 10, //每页的记录行数（*）
								pageList: [10, 20], //可供选择的每页的行数（*）
								clickToSelect: true,
							 	columns: [{
							 		
									checkbox: true
								},
								 {
									 field: columns[0].split(',')[0],
								     visible:false,
								     width:'10%',
								     align: 'center'
							    },
							    {
								 	field: columns[1].split(',')[0],
							        title: '编号',
							        width:'10%',
							        align: 'center'
							    }, {
							        field: columns[2].split(',')[0],
							        title: '用户名',
							        align: 'center'
							    }, {
							        field: columns[3].split(',')[0],
							        title: '姓名',
							        align: 'center'
							    },
							    {
							        field: columns[5].split(',')[0],
							        title: '邮箱',
							        align: 'center'
							    },
							    {
							        field: columns[6].split(',')[0],
							        title: '最近登录',
							        align: 'center'
							    },
							    {
							        field: columns[7].split(',')[0],
							        title: '上次登录IP',
							        align: 'center'
							    },
							    { 
							    	title: "操作", 
							    	align: "center",
							    	formatter:"actionFormatter",
					                }]
						});
					
				} 
				 function queryParams(params) {
					return {
						size : params.limit,
						page : params.pageNumber,
						userName:$("#nav-search-input").val(),
						lastLoginStart:$("#lastLoginStart").val(),
						lastLoginEnd:$("#lastLoginEnd").val(),
						role_id:$("#role_id").val(),
						del_flag: $("input[name='F_STATUS']:checked").val()
						
					};
				} 
				 
				 
				 
				 function actionFormatter(value, row, index) {
					
					 if(row.del_flag=='1'){
						 return  [
						            '<a class="btn btn-app btn-mini btn-info" title="恢复" onclick="revertUser(\''+row.user_ID+'\');"><i class="icon-reply"></i></a>&nbsp;&nbsp;&nbsp;',
						        ].join('');
					 }else{
						 return  [
						            '<a class="btn btn-app btn-mini btn-info" title="编辑" onclick="editUser(\''+row.user_ID+'\');"><i class="icon-edit"></i></a>&nbsp;&nbsp;&nbsp;',
									'<a class="btn btn-app btn-mini btn-danger" title="删除" onclick="delUser(\''+row.user_ID+'\');"><i class="icon-trash"></i></a>'
						        ].join(''); 
					 }
					
				 }
				 
				
			
				 
				 
				 function search(){
						$('#userTable').bootstrapTable('refresh',{
							  url: '<%=basePath%>user/userTable.do',
							  method: 'post', //请求方式（*）
								striped: true, //是否显示行间隔色
								cache: false, //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
								pagination: true, //是否显示分页（*）
								sortable: false, //是否启用排序
								sortOrder: "asc", //排序方式
								singleSelect : false,
								queryParams: queryParams, //传递参数（*）
								sidePagination: "server", //分页方式：client客户端分页，server服务端分页（*）
								queryParamsType : "limit",
								pageNumber: 1, //初始化加载第一页，默认第一页
								pageSize: 5, //每页的记录行数（*）
								pageList: [5, 10], //可供选择的每页的行数（*）
								clickToSelect: true,
						});
					}
		
		//导出excel
		function toExcel(){
			var USERNAME = $("#nav-search-input").val();
			var lastLoginStart = $("#lastLoginStart").val();
			var lastLoginEnd = $("#lastLoginEnd").val();
			var ROLE_ID = $("#role_id").val();
			window.location.href='<%=basePath%>user/excel.do?USERNAME='+USERNAME+'&lastLoginStart='+lastLoginStart+'&lastLoginEnd='+lastLoginEnd+'&ROLE_ID='+ROLE_ID;
		}
		
		//打开上传excel页面
		function fromExcel(){
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="EXCEL 导入到数据库";
			 diag.URL = '<%=basePath%>user/goUploadExcel.do';
			 diag.Width = 300;
			 diag.Height = 150;
			 diag.CancelEvent = function(){ //关闭事件
				 if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
					 if('${page.currentPage}' == '1'){
						 top.jzts();
						 setTimeout("self.location.reload()",100);
					 }else{
						 nextPage('${page.currentPage }');
					 }
				}
				diag.close();
			 };
			 diag.show();
		}
		
		
		</script>
	</body>
</html>

